<template>
  <div>
    <input type="file" @change="handleFileUpload" />
  </div>
</template>


<script>
import * as XLSX from 'xlsx';

/* load 'fs' for readFile and writeFile support */
export default {
  name: 'WorkspaceJsonJSTest',

  data() {
    return {

    };
  },
  created(){
  },
  mounted() {

  },

  methods: {
    handleFileUpload(event) {
      const file = event.target.files[0];
      const reader = new FileReader();
      reader.onload = (e) => {
        const data = new Uint8Array(e.target.result);
        const workbook = XLSX.read(data, { type: 'array' });
        console.dir(workbook)
        const sheetName = workbook.SheetNames[0];
        const worksheet = workbook.Sheets[sheetName];
        const jsonData = XLSX.utils.sheet_to_json(worksheet, { header: 1 });
 
        // 检查空行
        const hasEmptyRow = jsonData.some((row) => {
          return !row[0]; // 假设第一列为空就认为是空行
        });
 
        if (hasEmptyRow) {
          console.log('数据无空行，处理数据:', jsonData);
        } else {
          // 处理数据
          console.log('数据无空行，处理数据:', jsonData);
        }
      };
      reader.readAsArrayBuffer(file);
    },
  },
};
</script>

<style lang="scss" scoped>
</style>